package com.ljfiction.book.activitys;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.ljfiction.book.Baner.ShenqinggaochouBean;
import com.ljfiction.book.R;
import com.ljfiction.book.http.HttpManager;
import com.ljfiction.book.tools.SettingManager;
import com.lzy.okhttputils.OkHttpUtils;
import com.lzy.okhttputils.callback.StringCallback;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Response;

public class ApplymoneyActivity extends BaseActivity {

    @BindView(R.id.back_applymoney)
    ImageView backApplymoney;

    @BindView(R.id.bianjiname)
    TextView bianjiname;
    @BindView(R.id.bianjiqq)
    TextView bianjiqq;
    @BindView(R.id.moresay)
    TextView moresay;
    @BindView(R.id.zebianimage)
    ImageView zebianimage;
    private ShenqinggaochouBean sqgcBean;
    private String url;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_applymoney);
        ButterKnife.bind(this);
        intData();
    }

    private void intData() {
        OkHttpUtils.get(HttpManager.IP + "/getApplyForRoyalties")

                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(String s, Call call, Response response) {
                        try {
                            Gson g = new Gson();
                            sqgcBean = g.fromJson(s, ShenqinggaochouBean.class);
                            if (sqgcBean.getReturnCode() == 200) {
                                bianjiname.setText(sqgcBean.getData().getName());
                                bianjiqq.setText("点击聊天：QQ " + sqgcBean.getData().getIphone());
                                bianjiname.setText(sqgcBean.getData().getName());
                                moresay.setText(sqgcBean.getData().getViewInfo());
                                Glide.with(ApplymoneyActivity.this).load(sqgcBean.getData().getHadeImg()).into(zebianimage);
                            } else {
                                showToast(sqgcBean.getMsg());
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });
    }


    @OnClick({R.id.back_applymoney, R.id.bianjiqq})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_applymoney:
                goBack();
                break;
            case R.id.bianjiqq:
                try {
                    if (sqgcBean!=null&&sqgcBean.getData().getIphone()!=null){
                        //uin是发送过去的qq号码
                        url = "mqqwpa://im/chat?chat_type=wpa&uin="+sqgcBean.getData().getIphone();
                    }else {
                        //第二种方式：可以跳转到添加好友，如果qq号是好友了，直接聊天
                        url = "mqqwpa://im/chat?chat_type=wpa&uin=3310635242";//uin是发送过去的qq号码
                    }

                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                } catch (Exception e) {
                    e.printStackTrace();
                    showToast( "请检查是否安装QQ");
                }
                break;
        }
    }
}
